package ubcns.lib.spinner;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SpinnerAdapter extends ArrayAdapter<String>{

	private Context context;
	private ArrayList<String> items = new ArrayList<String>();
	private int mPosition;
	
	public SpinnerAdapter(Context context, int textViewResourceId, ArrayList<String> objects, int position) {
		super(context, textViewResourceId, objects);
		
		this.items = (ArrayList<String>) objects;
		this.context = context;
		this.mPosition = position;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		
		 if (convertView == null) {
             LayoutInflater inflater = LayoutInflater.from(context);
             convertView = inflater.inflate(
                     android.R.layout.simple_spinner_dropdown_item, parent, false);
         }
  
         TextView tv = (TextView) convertView.findViewById(android.R.id.text1);
         tv.setText(items.get(position));
         tv.setTextColor(Color.BLUE);
         tv.setTextSize(17);
         tv.setHeight(50);
         
         return convertView;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		 if (convertView == null) {
             LayoutInflater inflater = LayoutInflater.from(context);
             convertView = inflater.inflate(
                     android.R.layout.simple_spinner_item, parent, false);
         }
  
         TextView tv = (TextView) convertView.findViewById(android.R.id.text1);
         if(mPosition == 0){
             tv.setText(items.get(position));
         }else{
        	 tv.setText(items.get(mPosition));
         }
         tv.setTextSize(17);
         
         return convertView;
		
	}
	
	
}
